import { ccs } from "./services";

export class touchExd {
    target: Object = null;
    static touchScale(node: cc.Node, cb: Function, targetNode?) {
        // this.target = targetNode;
        node.on(cc.Node.EventType.TOUCH_END, (target, data) => {
            this.scaleInAndOutAction(node, true);
            cb.call(targetNode, target, data);
        })
    }
    static touchEvent(node: cc.Node, cb: Function, targetNode?) {
        node.on(cc.Node.EventType.TOUCH_END, (target, data) => {
            cb.call(targetNode, target, data);
        })
    }
    static scaleInAndOutAction(node:cc.Node, isPlay:boolean = false, scale:number = 1, time:number = 0.1, scaleIn:number = 1.5, scaleOut: number = 1) {
        cc.Tween.stopAllByTarget(node);
        if(isPlay) {
            scale = scale || node.scaleX;
            cc.tween(node)
            .to(time, {scale: scale * scaleIn}).to(time, {scale: scale * scaleOut})
            .start();
        }
    }
    
}